#include "widget.h"
#include "./ui_widget.h"
#include "sync-layer/composer.h"
#include <QPainter>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    setWindowTitle("Demo for SyncLayer Module");

    timer = new QTimer(this);
    connect(timer, &QTimer::timeout, this, [this]{ this->update(); });
    timer->start(20);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event)

    // 更新图层
    COMPOSER->update(width(), height());

    QPainter painter(this);

    // 创建空白画布
    QPixmap pixmap(width(), height());
    pixmap.fill(Qt::transparent);

    // 融合图层
    COMPOSER->compose(pixmap);

    // 绘制图层
    painter.drawPixmap(0, 0, pixmap);
}
